<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../fonts/iconfont.css" />
		<link rel="stylesheet" href="../css/homePage.css" />	
		<style>
			.mui-bar-nav{background:#e3393c}
			.mui-title{color:#fff}
		</style>
	</head>
	<body > 
		<header class="mui-bar mui-bar-nav" style=""id="index-head">
			<!--<button id='moreVshop' class=" mui-pull-left mui-btn-link"><img src="../images/h01.png"/></button>-->
			<h1 id="title" class="mui-title">主页</h1>
			
			<!--<button id='moreVshop' class=" mui-pull-right mui-btn-link">更多</button>-->
		</header> 
		<footer>
			<nav class="mui-bar mui-bar-tab">
				<a id="defaultTab" class="mui-tab-item mui-active subpage-btn " data-href="./home3.html">
					<span class="mui-icon iconfont icon-home"></span><br>
					<span class="mui-tab-label">主页</span>
					    
				</a>     
				<a class="mui-tab-item" id="goVshop" > 
					<span class="mui-icon iconfont icon-dianpu"></span>  
					<span class="mui-tab-label">直营店</span>
				</a>
				<a class="mui-tab-item" id="goRechat">
					<span class="mui-icon iconfont icon-liaotian" ></span>
					<span class="mui-tab-label">睿信</span>
				</a>
				<a class="mui-tab-item subpage-btn"  id="goOA" data-href="../OA/index.html">
					<span class="mui-icon iconfont icon-biji" ></span>
					<span class="mui-tab-label">办公</span>
				</a>
				<a class="mui-tab-item subpage-btn"  id="goCenter"data-href="../myCenter/index.html">
					<span class="mui-icon iconfont icon-wode"></span>
					<span class="mui-tab-label">个人中心</span>
				</a>    
			</nav>
		</footer>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript" charset="utf-8">
			//mui初始化
			mui.init();
			var subpages = ['./home3.html','../OA/index.html','../myCenter/index.html'];
			var subpage_style = {
				top: '44px',
				bottom: '50px'
			};
			var aniShow = {}; 
			 
			
			//创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
//				plus.nativeUI.Waiting();
				plus.screen.lockOrientation("portrait-primary"); // 仅支持竖屏显示，为了测试添加
				plus.navigator.setStatusBarBackground("#e3393c");
				plus.navigator.setStatusBarStyle("UIStatusBarStyleBlackOpaque");
				var self = plus.webview.currentWebview();							
				if(self.children().length<=3){
					for (var i = 0; i < 3; i++) {
						var temp = {};
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
						if (i > 0) {
							sub.hide();
						}else{
							temp[subpages[i]] = "true";
							mui.extend(aniShow,temp);
						}
						self.append(sub); 
					}
				}
				
				//当前激活选项
				var activeTab = subpages[0];
				var title = document.getElementById("title");
				var extras = self.extras;
				
				 //选项卡点击事件
				mui('.mui-bar-tab').on('tap', 'a.subpage-btn', function(e) {
					var targetTab = this.getAttribute('data-href')						
					if (targetTab == activeTab) {
						return;
					}			
					var titleName= this.querySelector('.mui-tab-label').innerHTML;					
					//判断用户是否有权限进入oa
					if(this.id=="goOA"){
						if(himall.isLogin()){
								console.log('进入OA')
						}else{ 
							e.stopPropagation();
							showLogin('','/');		 					    
							return;	
							console.log('oa测试3')
						} 
						
						var userId=plus.storage.getItem("userId")
						console.log(userId);
						mui.ajax(url+'OA/CheckUser',{
							data:{
								userId:549,
								webToken:'rqlh', 
							},
							dataType:'json',
							type:'post',					
							timeout:10000,
							success:function(data){	
								console.log("进来了啊啊");
								if(data.Code=="000"){
									title.innerHTML = titleName																		
									//显示目标选项卡
									if(mui.os.ios||aniShow[targetTab]){
										plus.webview.show(targetTab);
									}else{ 
										var temp = {};
										temp[targetTab] = "true";
										mui.extend(aniShow,temp);
										plus.webview.show(targetTab,"fade-in",300);
									}									
									//隐藏当前;
									plus.webview.hide(activeTab); 
									//更改当前活跃的选项卡
									activeTab = targetTab;
									console.log('oa测试2')
								}else{
									e.stopPropagation();
									plus.nativeUI.toast("对不起,该用户没有权限");
								}
							},
							error:function(xhr,type,errorThrown){
								e.stopPropagation();
								plus.nativeUI.toast("连接错误,请检查网络");
								console.log("连接错误,请检查网络");
								   
							}	
						})						
					}else{
						console.log(titleName)				
						title.innerHTML = titleName
						//显示目标选项卡
						if(mui.os.ios||aniShow[targetTab]){
							plus.webview.show(targetTab);
							console.log(targetTab)  
						}else{
							var temp = {};
							temp[targetTab] = "true"; 
							mui.extend(aniShow,temp);
							plus.webview.show(targetTab,"fade-in",300);
						}
						//隐藏当前;
						plus.webview.hide(activeTab);
						console.log(titleName+'2')
						//更改当前活跃的选项卡
						activeTab = targetTab;
					}
				});
				 //自定义事件，模拟点击“首页选项卡”
				document.addEventListener('gohome', function() {
					console.log('自定义事件')
					 var id = event.detail.id
					 var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
					 if(id=='index'){
					 	var defaultTab = document.getElementById('defaultTab');
						//模拟首页点击
						mui.trigger(defaultTab, 'tap');
						//切换选项卡高亮						
						if (defaultTab !== current) {
						current.classList.remove('mui-active');
						defaultTab.classList.add('mui-active');
						}
					 }else{
					 	var goOA = document.getElementById("goOA");
						//模拟OA点击
						mui.trigger(goOA, 'tap');					
		                if (goOA !== current) {
		                    current.classList.remove('mui-active');
		                    goOA.classList.add('mui-active');
		                }
					 }
					
				});
				
				//去睿信
				document.getElementById('goRechat').addEventListener('tap',function(e){
					e.stopPropagation();
					var mainPage = null;
					
					//登陆判断
					if(himall.isLogin()){
						himall.openVW('./../IM/tab-webview-main.html');						
					}else{ 
						showLogin({id:'./IM/tab-webview-main.html'},'/');
					}  
				});
				
				//去商城
				document.getElementById("goVshop").addEventListener('tap',function (e) {
					  
					//阻止派发事件
					e.stopPropagation(); 
					himall.openVW('../market.html');
					 
				});
				
				himall.quitApp();
							
			});
			
		</script> 
	</body>

</html>